package cc.mrbird.management.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/map")
public class MapController{
    @Autowired
    private RestTemplate restTemplate;
    @GetMapping("/addressToLocation")
    public JSONObject addressToLocation(String address) {
            String url = "http://api.map.baidu.com/geocoder?address="+address+"&output=json&key=llALN3LfK9ce4ccuGAk5sSNODnbyLYx1";
            RestTemplate restTemplate = new RestTemplate();
            ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
            String body = forEntity.getBody();
            JSONObject jsonObject = JSONObject.parseObject(body);
            return jsonObject;
    }
}
